package pl.edu.mimuw.irs.rcp.controller.menu;

import java.util.List;

import org.eclipse.gef.ContextMenuProvider;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.jface.action.IMenuManager;

import pl.edu.mimuw.irs.rcp.controller.editor.IRSWorkflowEditor;
import pl.edu.mimuw.irs.rcp.controller.menu.builder.ContextMenuBuilderFactory;
import pl.edu.mimuw.irs.rcp.controller.menu.builder.IContextMenuBuilder;

/**
 * @author Jakub Rauch
 * Created on: 2009-05-18
 */
public class WorkflowContextMenuProvider extends ContextMenuProvider {

	// *** Attributes
	
	private ContextMenuBuilderFactory menuBuilderFactory;
	
	// *** Methods
	
	public WorkflowContextMenuProvider(EditPartViewer viewer, IRSWorkflowEditor editor) {
		super(viewer);
		menuBuilderFactory = new ContextMenuBuilderFactory();
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public void buildContextMenu(IMenuManager menu) {
		IContextMenuBuilder menuBuilder;
		
		List<EditPart> editParts = getViewer().getSelectedEditParts();
		
		menuBuilder = menuBuilderFactory.getContextMenuBuilder(editParts);
		if (menuBuilder != null) menuBuilder.build(menu);
	}
}
